package Crawler;

import org.apache.commons.io.FileUtils;
import redis.clients.jedis.Jedis;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

/**
 * 因为从文件中读入数据存入Redis过慢
 * 所以单写出一个脚本
 */


public class connectRedisPutUidConnum {

    public static void main(String[] args) throws IOException {
        //连接本地的 Redis 服务
        Jedis jedis = new Jedis("222.27.227.117", 6379);
        System.out.println("SUCCEED!");

        String fileName = "C:/Users/TING/code/java code/Weibo/UID_CONNUM_200+.txt";
        ArrayList lineList = new ArrayList();
        lineList = getUidList(fileName);
        for(int i=0;i<lineList.size();i++){
            String line = lineList.get(i).toString();
            jedis.lpush("follower:uid_connum",line);
            System.out.println("已成功将     "+line+"    加入队列");
        }


    }

    public static ArrayList getUidList(String fileName) {
        ArrayList uidList = new ArrayList();
        try {
            for (String line : FileUtils.readLines(new File(fileName))) {
                uidList.add(line);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return uidList;
    }

}
